// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __SCENELIGHTMAP_H_INCLUDED__
#define __SCENELIGHTMAP_H_INCLUDED__

#include <irrlicht.h>
#include "HierarchicalGrid3d.h"

#ifdef PFEXPORT
#include "PFExporter.h"
#endif

class SceneIlluminationMap
{
public:
	SceneIlluminationMap();
	virtual ~SceneIlluminationMap();
	
#ifndef PFEXPORT	
	void LoadFromFile(const char* filename);
#endif

	s32 GetIllumination(const irr::core::vector3df& pos);
	const irr::core::vector3df& GetRGBScale() { return m_rgbScale; }

#ifdef PFEXPORT
	void Compute(RoomMapInfo& info, s32 tileSize, s32 tileSizeZ);
	void SaveAscii(const char* fileName, u8* arr = 0);
	void SaveBinary(irr::io::IWriteFile& stream);
#endif

	s16 GetMinValue() { return m_minValue; }
	s16 GetMaxValue() { return m_maxValue; }

	

protected:
	irr::core::vector3df TileToWorldPosition(s32 i, s32 j, s32 k);
	void WorldToTilePosition(const irr::core::vector3df& pos, s32& i, s32& j, s32& k);
	s32 GetTileIndex(s32 i, s32 j, s32 k);
	u8 GetGrayscale(u32 color);
	bool HasNeighbours(u8* map, s32 i, s32 j, s32 k);

protected:
	s16 m_minValue;
	s16 m_maxValue;

	// light map world position
	irr::core::vector3df m_pos;
	
	// map dimensions
	s32 m_sizeX;
	s32 m_sizeY;
	s32 m_sizeZ;
	
	s32 m_tileSize;
	s32 m_tileSizeZ;
	
	s16 m_valueOffset;
	irr::core::vector3df m_rgbScale;

	typedef HGrid3d<u8, 0> LightHGrid;
	LightHGrid* m_hgrid;
};

#endif
